/**
 * 
 */
package com.gkwave.action.service;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gkwave.module.bean.MessageBean;
import com.gkwave.module.dao.EmailDAO;
import com.gkwave.module.dao.GymYogaDAO;

/**
 * @author Administrator
 *
 */
public class HealthCareGymYogaRegistrationService extends BaseService {

	/**
	 * 
	 */
	private static final long serialVersionUID = -9046395175612060894L;

	/**
	 * 
	 */
	public HealthCareGymYogaRegistrationService() {
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see com.gkwave.action.service.BaseService#procesRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public void procesRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		/*
		 * idType (1 - Gym ;2 - Yoga)
		*/ 
		out = response.getWriter();
		String idType = request.getParameter("idType");
		String id = request.getParameter("id");
		String idUser = request.getParameter("idUser");
		String nrTotalSeatCapacity = request.getParameter("nrTotalSeatCapacity");
		String idSlot = request.getParameter("idSlot");
		String idAssociate=request.getParameter("idAssociate");
		String nmName=request.getParameter("nmName");
		String nmLocation=request.getParameter("nmLocation");
		String inGender=request.getParameter("inGender");
		Integer id_type = -1;
		Integer id_ = -1;
		Integer id_user = -1;
		Integer nr_total_seat_capacity = -1;
		MessageBean bean = new MessageBean();
		if(idType!=null && 
		   id!=null && 
		   idUser!=null && 
		   nrTotalSeatCapacity!=null && 
		   idSlot != null &&
		   idAssociate!=null && 
		   nmName!=null && 
		   nmLocation!=null && 
		   inGender!=null ){
			GymYogaDAO dao = new GymYogaDAO();
			id_type = Integer.parseInt(idType);
			id_ = Integer.parseInt(id);
			id_user = Integer.parseInt(idUser);
			nr_total_seat_capacity = Integer.parseInt(nrTotalSeatCapacity);
			String subject = null;
			String idEmail = null;
			if(id_type == 1){
				subject = "Gym Registration";
				bean = dao.doGymRegister(id_user,id_,nr_total_seat_capacity,idSlot,idAssociate,nmName,nmLocation,inGender);
			}else if(id_type == 2){
				subject = "Yoga Registration";
				bean = dao.doYogaRegister(id_user,id_,nr_total_seat_capacity,idSlot,idAssociate,nmName,nmLocation,inGender);
			}
			if(bean.getStatus().equals("Success")){
				StringBuffer messageContent = new StringBuffer();
				messageContent.append(subject);
				messageContent.append("\n====================");
				messageContent.append("\nName : " + nmName);
				messageContent.append("\nAssociate Id : " + idAssociate);
				messageContent.append("\nGender : " + inGender);
				messageContent.append("\nLocation : " + nmLocation);
				idEmail = dao.getEmailId(id_,id_type);
				sendEmailNotification(subject, messageContent, idEmail);
			}
		} else{
			xmlResponse = "Input is empty";
		}
		xmlResponse = bean.marsel(bean);
		System.out.println(xmlResponse);
		out.println(xmlResponse);
	}

	private void sendEmailNotification(String subject, StringBuffer messageContent, String idEmail) {
		// TODO Auto-generated method stub
		EmailDAO.sendEmailNotification("[SMARTC Notification] " + subject, messageContent.toString(), new String[]{idEmail});
	}
}
